import aiomysql
from tornado import ioloop


async def go():
    pool = await aiomysql.create_pool(host='127.0.0.1', port=3306,
                                      user='root', password='',
                                      db='messages', charset="utf8")
    async with pool.acquire() as conn:
        async with conn.cursor(cursor=aiomysql.cursors.DictCursor) as cur:
            await cur.execute("select * from messages")
            result = await cur.fetchone()
            print(result)
    pool.close()
    await pool.wait_closed()


if __name__ == '__main__':
    io_loop = ioloop.IOLoop.current()
    io_loop.run_sync(go)
